/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package livro.frames;

import livro.control.BookFameDadosEdit;
import livro.control.BookFrameDadosAlterarDeletar;
import livro.control.BookFrameDadosSave;
import livro.control.BookFrameDadosUpdate;
import livro.control.BookFrameDadosAlterarRestaurar;
import bibliinfo.FrameMain;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import javax.swing.table.DefaultTableModel;
import livro.model.LivroDao;
import livro.model.LivroExe;
import utilitarios.Validar;

/**
 *
 * @author Ar0n
 */
public class BookFrameAltera extends javax.swing.JInternalFrame {

    /**
     * Creates new form BookFrame
     */
    public BookFrameAltera() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTAutor = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jTTitulo = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jTEditora = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jTISBN = new javax.swing.JTextField();
        jTQuant = new javax.swing.JTextField();
        jDesktop = new javax.swing.JDesktopPane();
        jLQuant = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jTBSim = new javax.swing.JToggleButton();
        jTBNao = new javax.swing.JToggleButton();
        jLabel24 = new javax.swing.JLabel();
        jBAlterar = new javax.swing.JButton();
        jBExcluirReal = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jDesktopExcluir = new javax.swing.JDesktopPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable = new javax.swing.JTable();

        jTAutor.setPreferredSize(new java.awt.Dimension(0, 10));
        jTAutor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTAutorKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTAutorKeyReleased(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel19.setText("<html>Título:<b color=\"red\">*</b></html>");
        jLabel19.setPreferredSize(new java.awt.Dimension(20, 15));

        jLabel20.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel20.setText("<html>Autor:<b color=\"red\">*</b></html>");
        jLabel20.setPreferredSize(new java.awt.Dimension(20, 15));

        jTTitulo.setPreferredSize(new java.awt.Dimension(0, 10));
        jTTitulo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTTituloKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTTituloKeyReleased(evt);
            }
        });

        jLabel21.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel21.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel21.setText("<html>Editora:<b color=\"red\">*</b></html>");
        jLabel21.setPreferredSize(new java.awt.Dimension(20, 15));

        jTEditora.setPreferredSize(new java.awt.Dimension(0, 10));
        jTEditora.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTEditoraKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTEditoraKeyReleased(evt);
            }
        });

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel22.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel22.setText("Pode ser Emprestádo:");
        jLabel22.setPreferredSize(new java.awt.Dimension(20, 15));

        jTISBN.setPreferredSize(new java.awt.Dimension(0, 10));
        jTISBN.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTISBNKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTISBNKeyReleased(evt);
            }
        });

        jTQuant.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTQuant.setText("9999");
        jTQuant.setEnabled(false);
        jTQuant.setPreferredSize(new java.awt.Dimension(0, 10));
        jTQuant.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTQuantFocusLost(evt);
            }
        });
        jTQuant.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTQuantKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTQuantKeyReleased(evt);
            }
        });

        jDesktop.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jDesktopAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        jLQuant.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLQuant.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLQuant.setText("Quantidade de Exemplares:");
        jLQuant.setPreferredSize(new java.awt.Dimension(20, 15));

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel23.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel23.setText("Status do Exemplar");
        jLabel23.setPreferredSize(new java.awt.Dimension(20, 15));

        jTBSim.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTBSim.setText("Sim");
        jTBSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTBSimActionPerformed(evt);
            }
        });

        jTBNao.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTBNao.setText("Não");
        jTBNao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTBNaoActionPerformed(evt);
            }
        });

        jLabel24.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel24.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel24.setText("<html>ISBN:<b color=\"red\">*</b></html>");
        jLabel24.setPreferredSize(new java.awt.Dimension(20, 15));

        jBAlterar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBAlterar.setText("Alterar");
        jBAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAlterarActionPerformed(evt);
            }
        });

        jBExcluirReal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBExcluirReal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_livro/1367341322_delete.png"))); // NOI18N
        jBExcluirReal.setText("Excluir");
        jBExcluirReal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBExcluirRealActionPerformed(evt);
            }
        });

        jDesktopExcluir.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jDesktopExcluirAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        jScrollPane1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jTable.setModel(defaultTable);
        jTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableMouseClicked(evt);
            }
        });
        jTable.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTableFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(jTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktop)
            .addComponent(jSeparator1)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jDesktopExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45))
            .addGroup(layout.createSequentialGroup()
                .addGap(114, 114, 114)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLQuant, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(35, 35, 35)
                        .addComponent(jTQuant, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jBAlterar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jTISBN, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jTEditora, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jTAutor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jTTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42)
                .addComponent(jBExcluirReal, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 45, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jDesktopExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTAutor, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTEditora, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTISBN, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTQuant, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLQuant, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(35, 35, 35)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jBExcluirReal, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
                        .addComponent(jDesktop, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jDesktopAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jDesktopAncestorAdded
        escolheComp("edit");
    }//GEN-LAST:event_jDesktopAncestorAdded

    private void jBAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAlterarActionPerformed
       jTQuant.setEnabled(true);
       jLQuant.setText("<html>Quantidade de Exemplares:<b color=\"red\">*</b></html>");
    }//GEN-LAST:event_jBAlterarActionPerformed

    private void jTQuantFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTQuantFocusLost
       
        int a = Integer.parseInt(jTQuant.getText());
        if(a == 0){
            JOptionPane.showMessageDialog(FrameMain.bookFrameAltera,
                    "<html>O número de livros não pode ser igual a <b color=\"red\">zero</b></html>", "", 1);
        }else{
            jTQuant.setEnabled(false);
            jLQuant.setText("Quantidade de Exemplares:");
        }   
        
    }//GEN-LAST:event_jTQuantFocusLost

    private void jTBSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTBSimActionPerformed
        try{
            alterarPodeEmp(true);
            for(LivroExe exe : FrameMain.bookFrameMain.listaLivroRealQuero){
                int i = FrameMain.bookFrameAltera.jTable.getSelectedRow();
                
                int l = Integer.parseInt(FrameMain.bookFrameAltera.jTable.getValueAt(i, 0).toString());                
                System.out.println(l);
                if(l == exe.getNumSequencia()){
                    System.out.println(exe.getPodeEmprestar());
                    exe.setPodeEmprestar(true);                   
                    System.out.println(exe.getPodeEmprestar());
                }
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(FrameMain.bookFrameAltera, "Selecione um item da tabela", "", 1);
            alterarPodeEmp(false);
        }        
    }//GEN-LAST:event_jTBSimActionPerformed

    private void jTBNaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTBNaoActionPerformed
        try{
            alterarPodeEmp(false);
            for(LivroExe exe : FrameMain.bookFrameMain.listaLivroRealQuero){
                int i = FrameMain.bookFrameAltera.jTable.getSelectedRow();
                int l = Integer.parseInt(FrameMain.bookFrameAltera.jTable.getValueAt(i, 0).toString());                              
                System.out.println(l);
                if(l == exe.getNumSequencia()){
                    System.out.println(exe.getPodeEmprestar());
                    exe.setPodeEmprestar(false);                        
                    System.out.println(exe.getPodeEmprestar());
                }
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(FrameMain.bookFrameAltera, "Selecione um item da tabela", "", 1);
            alterarPodeEmp(true);
        }
    }//GEN-LAST:event_jTBNaoActionPerformed

    private void jDesktopExcluirAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jDesktopExcluirAncestorAdded
        DelouRes();
    }//GEN-LAST:event_jDesktopExcluirAncestorAdded

    private void jTTituloKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTTituloKeyPressed
        Validar.validaTexto(jTTitulo, 50);
    }//GEN-LAST:event_jTTituloKeyPressed

    private void jTTituloKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTTituloKeyReleased
        Validar.validaTexto(jTTitulo, 50);
    }//GEN-LAST:event_jTTituloKeyReleased

    private void jTAutorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTAutorKeyPressed
        Validar.validaTexto(jTAutor, 50);
    }//GEN-LAST:event_jTAutorKeyPressed

    private void jTAutorKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTAutorKeyReleased
        Validar.validaTexto(jTAutor, 50);
    }//GEN-LAST:event_jTAutorKeyReleased

    private void jTEditoraKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTEditoraKeyPressed
        Validar.validaTexto(jTEditora, 50);
    }//GEN-LAST:event_jTEditoraKeyPressed

    private void jTEditoraKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTEditoraKeyReleased
        Validar.validaTexto(jTEditora, 50);
    }//GEN-LAST:event_jTEditoraKeyReleased

    private void jTISBNKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTISBNKeyPressed
        Validar.validaNum(jTISBN, 13);
    }//GEN-LAST:event_jTISBNKeyPressed

    private void jTISBNKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTISBNKeyReleased
        Validar.validaNum(jTISBN, 13);
    }//GEN-LAST:event_jTISBNKeyReleased

    private void jTQuantKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTQuantKeyPressed
        Validar.validaNum(jTQuant, 4);
    }//GEN-LAST:event_jTQuantKeyPressed

    private void jTQuantKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTQuantKeyReleased
        Validar.validaNum(jTQuant, 4);
    }//GEN-LAST:event_jTQuantKeyReleased

    private void jBExcluirRealActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBExcluirRealActionPerformed
        int i = JOptionPane.showConfirmDialog(FrameMain.bookFrameAltera, 
                "Você realmente deseja excluir este exemplar?", "", 0);
        if(i == 0){
            int tamanho = FrameMain.bookFrameAltera.jTable.getSelectedRow();
            if(tamanho == 1){
                JOptionPane.showMessageDialog(FrameMain.bookFrameAltera, 
                        "<html>Não é possivel <b color=\"red\">excluir todos</b> os exemplares<br />"+
                        "E manter o cadastro do livro</html>", "", 2);
            }else{
                LivroExe exe = new LivroExe();
                LivroDao dao = new LivroDao();
                exe.setISBN(FrameMain.bookFrameMain.ISBNSelecionado);      
                int m = FrameMain.bookFrameAltera.jTable.getSelectedRow();
                exe.setNumSequencia(Integer.parseInt(FrameMain.bookFrameAltera.jTable.getValueAt(m, 0).toString()));
                exe.setNumSequencia(exe.getNumSequencia() - 1);
                boolean resp = dao.ExcluirReal(exe);
                if(resp == true){
                                        
                    //deletando posição da tabela                    
                    FrameMain.bookFrameAltera.defaultTable.removeRow(m);
                }            
            }           
        }       
    }//GEN-LAST:event_jBExcluirRealActionPerformed

    private void jTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableMouseClicked
      try{
        int a = FrameMain.bookFrameAltera.jTable.getSelectedRow();
        a = Integer.parseInt(FrameMain.bookFrameAltera.jTable.getValueAt(a, 0).toString());
          for(LivroExe exe : FrameMain.bookFrameMain.listaLivroRealQuero){
              if(a == exe.getNumSequencia()){                
                  if(exe.getPodeEmprestar() == true){
                      FrameMain.bookFrameAltera.alterarPodeEmp(true);         
                  }else{
                      FrameMain.bookFrameAltera.alterarPodeEmp(false);         
                  }
              }          
          }    
      }catch(Exception e){
          
      }      
    }//GEN-LAST:event_jTableMouseClicked

    private void jTableFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTableFocusGained
        try{
            int a = FrameMain.bookFrameAltera.jTable.getSelectedRow();
            a = Integer.parseInt(FrameMain.bookFrameAltera.jTable.getValueAt(a, 0).toString());
            for(LivroExe exe : FrameMain.bookFrameMain.listaLivroRealQuero){
                if(a == exe.getNumSequencia()){                
                    if(exe.getPodeEmprestar() == true){
                        FrameMain.bookFrameAltera.alterarPodeEmp(true);         
                    }else{
                        FrameMain.bookFrameAltera.alterarPodeEmp(false);         
                    }
                }          
            }           
        }catch(Exception e){
        
        }
         
    }//GEN-LAST:event_jTableFocusGained

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jBAlterar;
    private javax.swing.JButton jBExcluirReal;
    private static javax.swing.JDesktopPane jDesktop;
    public javax.swing.JDesktopPane jDesktopExcluir;
    private javax.swing.JLabel jLQuant;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    public javax.swing.JTextField jTAutor;
    private javax.swing.JToggleButton jTBNao;
    private javax.swing.JToggleButton jTBSim;
    public javax.swing.JTextField jTEditora;
    public javax.swing.JTextField jTISBN;
    public javax.swing.JTextField jTQuant;
    public javax.swing.JTextField jTTitulo;
    public javax.swing.JTable jTable;
    // End of variables declaration//GEN-END:variables
    //atributos
    public DefaultTableModel defaultTable = new DefaultTableModel(null, new String []{""});
    //métodos
    private static boolean estado;
    public static Map<String, JInternalFrame> mapa = new HashMap<String, JInternalFrame>();
    private boolean excluir;
    public BookFrameDadosAlterarDeletar jBExcluir = new BookFrameDadosAlterarDeletar();
    public BookFrameDadosAlterarRestaurar jBRestaurar = new BookFrameDadosAlterarRestaurar();
    //métodos
    public void setEstado(boolean estado){
        this.estado = estado;
    }
    public boolean getEstado(boolean estado){
        return estado;
    }

    public boolean isExcluir() {
        return excluir;
    }

    public void setExcluir(boolean excluir) {
        this.excluir = excluir;
    }
    
    /**
     método usado para formatar os internalFrames chamados dentro deste
     */
    
    public static void fortama(int a){
        //retirando bordas do internalJframe
        ((BasicInternalFrameUI)mapa.get("frame"+a).getUI()).setNorthPane(null);
        mapa.get("frame"+a).setBorder(null);
        //pegando dimenções do JDesktop no qual ele esta encapsulado
        mapa.get("frame"+a).setBounds(0, 0, jDesktop.getWidth(), jDesktop.getHeight());
        mapa.get("frame"+a).setResizable(false); 
    }
    
    /**
      método que me informara qual sera o internalFrame de complemento que eu usarei
     */
    public static void escolheComp(String frame){
    
        if(frame.equalsIgnoreCase("save") == true){
            BookFrameDadosSave frameSalve = new BookFrameDadosSave();
            jDesktop.add(frameSalve);
            frameSalve.show();
            mapa.put("frame1", frameSalve);
            fortama(1);     
        }else if (frame.equalsIgnoreCase("edit") == true){
            BookFameDadosEdit frameEdit = new BookFameDadosEdit();
            jDesktop.add(frameEdit);
            frameEdit.show();
            mapa.put("frame2", frameEdit);
            fortama(2);
        }else if(frame.equalsIgnoreCase("update") == true){
            BookFrameDadosUpdate frameUpdate = new BookFrameDadosUpdate();
            jDesktop.add(frameUpdate);
            frameUpdate.show();
            mapa.put("frame3", frameUpdate);
            fortama(3);
        }        
    }
    
    public void alterarPodeEmp(boolean b){
        if(b == true){
            jTBNao.setSelected(false);
            jTBSim.setSelected(true);
        }else{
            jTBNao.setSelected(true);
            jTBSim.setSelected(false);
        }
    }
    
    public void DelouRes(){
        if(excluir == true){
            jBExcluir.setVisible(true);
            jBRestaurar.setVisible(false);

            //retirando bordas do internalJframe
            ((BasicInternalFrameUI)jBExcluir.getUI()).setNorthPane(null);
            jBExcluir.setBorder(null);
            //pegando dimenções do JDesktop no qual ele esta encapsulado
            jBExcluir.setBounds(0, 0, jDesktopExcluir.getWidth(), jDesktopExcluir.getHeight());
            jBExcluir.setResizable(false);
            
        }else{
        
            jBExcluir.setVisible(false);
            jBRestaurar.setVisible(true);
            
            //retirando bordas do internalJframe
            ((BasicInternalFrameUI)jBRestaurar.getUI()).setNorthPane(null);
            jBRestaurar.setBorder(null);
            //pegando dimenções do JDesktop no qual ele esta encapsulado
            jBRestaurar.setBounds(0, 0, jDesktopExcluir.getWidth(), jDesktopExcluir.getHeight());
            jBRestaurar.setResizable(false);
        }
    }
    
    public void desabilitarCampos(){
        jTTitulo.setEditable(false);
        jTAutor.setEditable(false);
        jTEditora.setEditable(false);
        jTISBN.setEditable(false);
        
        jBAlterar.setEnabled(false);        
        jTBNao.setEnabled(false);
        jTBSim.setEnabled(false);
        jBExcluirReal.setEnabled(false);
        jBExcluir.jButton1.setEnabled(false);    
        
        jTable.setEnabled(false);
        
    }
    
    public void habilitarCampos(){
        jTTitulo.setEditable(true);
        jTAutor.setEditable(true);
        jTEditora.setEditable(true);
        jTISBN.setEditable(true);
        
        jBAlterar.setEnabled(true);        
        jTBNao.setEnabled(true);
        jTBSim.setEnabled(true);
        jBExcluirReal.setEnabled(true);
        jBExcluir.jButton1.setEnabled(true);
        jBRestaurar.jButton1.setEnabled(true);
        
        jTable.setEnabled(true);
    }
}
